'use strict';

let fillZero = true;
let track = [];
let robots = [];

// one trip
function trip() {
  // console.log('robots:', robots.join(''));
  // console.log('track :', track.join(''));

  // single move
  robots.unshift(0);

  for (let i = 0, length = track.length > robots.length ? robots.length : track.length; i < length; i++) {
    if (robots[i]) {
      switch (track[i]) {
        case 0:
          track[i] = 1;
          break;
        case 1:
          track[i] = 2;
          robots[i] = 0;
          break;
        case 2:
          break;
        default:
          break;
      }
    } else {
      switch (track[i]) {
        case 0:
          break;
        case 1:
          track[i] = 0;
          robots[i] = 1;
          break;
        case 2:
          track[i] = 1;
          break;
        default:
          break;
      }
    }
  }

  // terminal move
  if (robots.length > track.length) {
    if (robots[robots.length - 1]) {
      track.push(2);
    }
    robots.pop();
  }

  // clear the zeros ahead the array
  if (!fillZero) {
    while (!(track[0] || robots[0])) {
      track.shift();
      robots.shift();
    }
  }

}

const TRACK_SIGN = { 0: '▁', 1: '▄', 2: '█' };
const ROBOT_SIGN = { 0: '□', 1: '■' };
const WIDTH_SIGN = { 0: '０', 1: '１', 2: '２' }; 